package com.wangdong.mijiqiqi;


import android.content.Intent;
import android.content.IntentFilter;
import android.net.ConnectivityManager;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.KeyEvent;
import android.view.View;

import com.wangdong.mijiqiqi.receiver.NetWorkStateReceiver;

public class MainActivity extends AppCompatActivity {
    NetWorkStateReceiver netWorkStateReceiver;

    @Override
    protected void onStart() {
        super.onStart();
        System.out.println("Mainstart");
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        System.out.println("MainonCreate");
    }

    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        System.out.println("MainonSaveInstanceState");
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        System.out.println("MainonKeyDown");
        return super.onKeyDown(keyCode, event);

    }

    @Override
    protected void onRestart() {
        super.onRestart();
        System.out.println("MainonRestart");
    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        System.out.println("MainonNewIntent");
    }

    @Override
    protected void onResume() {
        super.onResume();
    }

    @Override
    protected void onPause() {
        if (netWorkStateReceiver != null) {
            unregisterReceiver(netWorkStateReceiver);
        }
        super.onPause();
        System.out.println("MainonPause");

    }

    @Override
    protected void onStop() {
        super.onStop();
        System.out.println("MainonStop");
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        System.out.println("MainonDestroy");
    }

    public void wangdong(View view) {
        Intent[] intents = new Intent[]{new Intent(this, HomeActivity.class),
                new Intent(this, PeepActivity.class),
                new Intent(this, SeedActivity.class)};
        startActivities(intents);
    }

    public void zhuCeguangbo(View view) {

        if (netWorkStateReceiver == null) {
            netWorkStateReceiver = new NetWorkStateReceiver();
        }
        IntentFilter filter = new IntentFilter();

        filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
        registerReceiver(netWorkStateReceiver, filter);
        System.out.println("注册");
        super.onResume();
    }


}
